package com.atm.thirdplt.web.controller.system;

import com.atm.thirdplt.common.constant.Constants;
import com.atm.thirdplt.common.core.domain.AjaxResult;
import com.atm.thirdplt.common.core.domain.model.LoginBody;
import com.atm.thirdplt.core.web.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录验证
 *
 * @author atm
 */
@Api(tags = "系统登陆")
@RestController
public class SysLoginController
{
    @Autowired
    private SysLoginService loginService;

    /**
     * 登录方法
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @ApiOperation(value = "用户登陆", notes = "用户登陆")
    @ApiImplicitParam(name = "loginBody", value = "登陆信息实体", required = true, dataType = "LoginBody")
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), null,
                null);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }
}
